package com.falcon.controller.exam;

import com.falcon.mvc.domain.BasePager;
import com.falcon.mvc.domain.BaseResponse;
import com.falcon.mvc.base.IBaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

import com.falcon.domain.dos.ExamQuestionDO;
import com.falcon.domain.req.ExamQuestionQuery;
import com.falcon.domain.req.ExamQuestionRequest;
import com.falcon.service.IExamQuestionService;

@Slf4j
@RestController
@RequestMapping("/exam/examQuestion")
@Tag(name = "ExamQuestionController", description = "考试-接口")
public class ExamQuestionController  implements IBaseController {

    @Autowired
    private IExamQuestionService examQuestionService;

    @Operation(summary = "新增")
    @PostMapping("/save")
    public BaseResponse<Long> save(@Valid @RequestBody ExamQuestionRequest request) {

        Long id =  this.examQuestionService.save(request);

        return BaseResponse.success(id);
    }

    @Operation(summary = "修改")
    @PutMapping("/update/{id}")
    public BaseResponse<Boolean> update(@PathVariable Long id, @Valid @RequestBody ExamQuestionRequest request) {

        Boolean success =  this.examQuestionService.update(id, request);

        return BaseResponse.success(success);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/delete/{id}")
    public BaseResponse<Boolean> deleteById(@PathVariable Long id) {

        Boolean success =  this.examQuestionService.deleteById(id);

        return BaseResponse.success(success);
    }

    @Operation(summary = "批量删除")
    @PostMapping("/batchDelete")
    public BaseResponse<Integer> batchDelete(@RequestBody List<Long> ids) {

        Integer num =  this.examQuestionService.batchDelete(ids);

        return BaseResponse.success(num);
    }

    @Operation(summary = "查询基本信息")
    @GetMapping("/{id}")
    public BaseResponse<ExamQuestionDO> detail(@PathVariable Long id) {

        ExamQuestionDO examQuestionDo =  this.examQuestionService.queryById(id);

        return BaseResponse.success(examQuestionDo);
    }


    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public BaseResponse<List<ExamQuestionDO>> list(@RequestBody ExamQuestionQuery request) {

        List<ExamQuestionDO> list =  this.examQuestionService.queryList(request);

        return BaseResponse.success(list);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/pager")
    public BaseResponse<BasePager<ExamQuestionDO>> pager(@RequestBody ExamQuestionQuery request) {

        BasePager<ExamQuestionDO> pager =  this.examQuestionService.queryPager(request);

        return BaseResponse.success(pager);
    }


}

